<html>
<head><meta charset="utf-8"><title>Optimizing away `()`s and `!` pre-monomorphization? · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing.20away.20.60().60s.20and.20.60!.60.20pre-monomorphization.3F.html">Optimizing away `()`s and `!` pre-monomorphization?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212609993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing%20away%20%60%28%29%60s%20and%20%60%21%60%20pre-monomorphization%3F/near/212609993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing.20away.20.60().60s.20and.20.60!.60.20pre-monomorphization.3F.html#212609993">(Oct 07 2020 at 19:47)</a>:</h4>
<p>I'm very sad about PRs like <a href="https://github.com/rust-lang/rust/pull/72139">https://github.com/rust-lang/rust/pull/72139</a> that make the user experience worse to speed up compilation.</p>
<p>Any thoughts on the steps we'd need in mir-opt to compile away the excess cruft when implementing <code>fold</code> in terms of <code>try_fold</code>?  Folding away all the <code>ControlFlow::Break(!)</code> arms seems like it could be totally feasible in MIR, though it might be blocked on a bunch of inlining changes</p>



<a name="212611938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing%20away%20%60%28%29%60s%20and%20%60%21%60%20pre-monomorphization%3F/near/212611938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing.20away.20.60().60s.20and.20.60!.60.20pre-monomorphization.3F.html#212611938">(Oct 07 2020 at 20:02)</a>:</h4>
<p>I did add a mir-opt pass that removed branches on uninhabited enum variants which should do that. Like you said, the issue maybe that we need inlining to occur first.</p>



<a name="212613571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing%20away%20%60%28%29%60s%20and%20%60%21%60%20pre-monomorphization%3F/near/212613571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing.20away.20.60().60s.20and.20.60!.60.20pre-monomorphization.3F.html#212613571">(Oct 07 2020 at 20:15)</a>:</h4>
<p>what is worse about the user experience?</p>



<a name="212613590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing%20away%20%60%28%29%60s%20and%20%60%21%60%20pre-monomorphization%3F/near/212613590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing.20away.20.60().60s.20and.20.60!.60.20pre-monomorphization.3F.html#212613590">(Oct 07 2020 at 20:15)</a>:</h4>
<p>do you mean longer term, when users can implement <code>try_fold</code>?</p>



<a name="212615918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing%20away%20%60%28%29%60s%20and%20%60%21%60%20pre-monomorphization%3F/near/212615918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Optimizing.20away.20.60().60s.20and.20.60!.60.20pre-monomorphization.3F.html#212615918">(Oct 07 2020 at 20:37)</a>:</h4>
<p>Yes, that it forces people to implement <code>fold</code> even if they implement <code>try_fold</code>, when for the vast majority of iterators the default <code>fold</code>-via-<code>Result&lt;T, !&gt;</code> is perfectly fine.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>